
#ifndef __XML_DESCRIPTOR_H
#define __XML_DESCRIPTOR_H

#include <libxml/xpointer.h>
#include <apr-1/apr_pools.h>
#include "../db/KeyDB.h"
#include "DOMDocument.h"

/** Collection of XML tasks relating to the production and curation of
 * the XML descriptor accompanying workpacket dissemination. */
class XMLDescriptor
{
   public:
      XMLDescriptor();
      ~XMLDescriptor();
      int readEncrypted(KeyDB *keydb, const char *keyname, const char *filename, apr_pool_t *mp);
      int writeEncrypted(KeyDB *keydb, const char *keyname, const char *filename, apr_pool_t *mp);
      int readPlain(const char *filename);
      int readPlain(const char *buffer, int length);
      int writePlain(const char *filename);
      char *writePlain();
      char *getCapabilitiesString();
      apr_off_t getNumberOfBlocks();
      apr_off_t getUncompressedBlockSize();
      apr_off_t getCompressedEncryptedSize(int block);
      const char *calculateXORBlockHash(int numberofblocks);
      int allocateFileSystemBlocks(AllDBs *dbs, const char *store_uuid, const char *username, int *mustreverse, int *errmsg, apr_pool_t *mp, apr_off_t *sizeused);
      int allocateXMLDescribed(AllDBs *dbs, const char *store_uuid, const char *username, int *errmsg, const char *origination, apr_pool_t *mp, apr_off_t *sizeused);
      int generateXMLTreeForBlockTransfer(int *cancel, const char *cname, KeyPair *trialkey, const char *directorypath, apr_size_t blocksize, apr_pool_t *mp, int *blocks);
      int unlinkXMLTreeForBlockTransfer();
      void generateInitialDescriptor(const char *workname, const char *examplechain, const char *caps, int secondsmax);
   private:
      /** Pointer to the Document Object Model (DOM) object. */
      DOMDocument *domd;
      xmlNodePtr getBlockTransferNode();
      xmlNodePtr getBlockNode(int block);
};

#endif
